<template>
    <div>
        <el-carousel :interval="2000" type="card" height="300px">
             <el-carousel-item v-for="item in imgList" :key="item.id">
                     <img ref="banner_height" :src="item.idView" class="banner_image"/>
                </el-carousel-item>
        </el-carousel>
        <el-row>
            <el-col :span="6" class = "box" v-for="(o, index) in 3" :key="o" :offset="index > 0 ? 3 : 0">
            <el-card :body-style="{ padding: '0px' }" shadow = "always">
            <img src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" class="image">
            <div style="padding: 1%;">
                <span>好吃的汉堡</span>
            <div class="bottom clearfix">
                <time class="time">{{ currentDate }}</time>
                <el-button type="text" class="button">操作按钮</el-button>
            </div>
            </div>
            </el-card>
        </el-col>
    </el-row>
    </div>
</template>

<script>

export default {
  name:'index',
  data(){
        return {
            imgList: [
                {id:0,idView:require("@/assets/01.jpg")},
                {id:1,idView:require("@/assets/02.jpg")},
                {id:2,idView:require("@/assets/03.jpg")},
                {id:3,idView:require("@/assets/04.jpg")}            
            ],
          // 浏览器宽度
        screenWidth :0
      }
    },
     methods:{
              setSize:function () {
                // 通过浏览器宽度(图片宽度)计算高度
                this.bannerHeight = 400 / 1920 * this.screenWidth;
              },
      },
      mounted() {
              // 首次加载时,需要调用一次
              this.screenWidth =  window.innerWidth;
              this.setSize();
              // 窗口大小发生改变时,调用一次
              window.onresize = () =>{
              this.screenWidth =  window.innerWidth;
              this.setSize();
        }
  }
}
</script>

<style>
.banner_image {
  width:100%;
  height:inherit;
}/*设置图片宽度和浏览器宽度一致*/
.time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    color:black;
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
   .el-card {
    min-width: 300px;
    margin-right: 20px;
    transition: all .2s;
  }
  .el-card:hover{
    margin-top: -16px;
  }
</style>